package seiacpjava_a2.utilities;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.util.LinkedList;
import java.util.List;
import java.util.Random;

import javax.management.MXBean;

public class HashTableFileGenerator {

	public static void main(String[] args) {

		List<Integer> generatedNumbers = new LinkedList<>();
		int size = 1000;
		int maxNumber = 100000;
		String filePath = "c:/comp6411_files/ht_inputfile_1000Items.txt";

		StringBuffer output = new StringBuffer();
		Random randomNumberGenerator = new Random();
		int generatedNumber;

		while(generatedNumbers.size() < size) {
			generatedNumber = randomNumberGenerator.nextInt(maxNumber);
			if (!generatedNumbers.contains(generatedNumber)) {
				if ( generatedNumbers.size() < size -1 ){
				generatedNumbers.add(generatedNumber);
				output.append(generatedNumber + ",");
				}else
				{
					generatedNumbers.add(generatedNumber);
					output.append(generatedNumber);
				}
			}

		}

		writeToFile(output.toString(), filePath);
		System.out.println("Finished writing file " + filePath);
	}

	private static void writeToFile(String output, String filePath) {
		try {
			// Create file
			FileWriter fstream = new FileWriter(filePath);
			BufferedWriter out = new BufferedWriter(fstream);
			out.write(output);
			// Close the output stream
			out.close();
		} catch (Exception e) {// Catch exception if any
			System.err.println("Error: " + e.getMessage());
		}
	}

}
